package Servlet;

import Pojo.Journalism;
import Pojo.User;
import Service.ViceCheck;
import Service.ViceFindInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@WebServlet("/NewInfo") 
public class NewInfo extends HttpServlet {
//    发布文章
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        ViceFindInfo viceFindInfo = new ViceFindInfo();
        String title= req.getParameter("title");
        String simply= req.getParameter("simply");
        String content= req.getParameter("content");
        String type= req.getParameter("type");
        viceFindInfo.addnew(title,simply,content,type);
        ViceCheck viceCheck = new ViceCheck();
//        发布文章后重新加载
        List<Pojo.NewInfo> newInfo = viceCheck.findinfo(1);
        req.getSession().removeAttribute("newInfo");
        req.getSession().setAttribute("newInfo",newInfo);
        resp.sendRedirect(req.getContextPath()+"/infomanager.jsp");
    }


//    查用户信息
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        req.getSession().removeAttribute("users");
        ViceFindInfo viceFindInfo = new ViceFindInfo();
        List<User> users = viceFindInfo.finduserinfo();
        req.getSession().setAttribute("users",users);
        System.out.println(users);
    }
}
